<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
  <head>
    <style type="text/css">
        /* commented backslash hack \*/ 
        html, body{height:100%;} 
        /* end hack */
        html,body {margin:0;padding:0}
        #map{min-height:99%;height:auto;background:#ffffcc}
        * html #map{height:99%;}/* ie6 and under*/
    </style>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Where Am I?</title>
    <script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAVRwcp48C855kExP8gMQBuBQ2DvfD1rTaE23qrF0VOP3oS7NckRRqcvC-yPOWnbTpzgG3ZFH0ZRxRvQ"></script>
    <script src="extmaptypecontrol.js" type="text/javascript"></script>
    <script src="BDCCArrowedPolyline.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
      function initialize() {
        var map = new GMap2(document.getElementById("map"));
        map.enableScrollWheelZoom();
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.addControl(new GOverviewMapControl());
        
        /*function MiscControl() {
        }
        MiscControl.prototype = new GControl();
        MiscControl.prototype.initialize = function(map) {
            var boxDiv = document.createElement("div");
            boxDiv.innerHTML = '<font face=Arial size=-3>Rotas: <span id="rotas">?</span><br/>Where Am I? Copyright &copy; 2008 Wagner Sartori Junior. All Rights Reserved.';
            map.getContainer().appendChild(boxDiv);
        }
        MiscControl.prototype.getDefaultPosition = function() {
            return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(10, 60));
        }
        MiscControl.prototype.setButtonStyle_ = function(button) {
        }
        map.addControl(new MiscControl());*/
        
<?php
if ($_GET['data']):
    $data_inicio = $_GET['data']." 00:00:00";
    $data_fim = $_GET['data']." 23:59:59";
else:
    $data_inicio = date('Y-m-d H:i:s', mktime(date("H"), date("i"), date("s"), date("m"), date("d")-1, date("Y")));
    $data_fim = date('Y-m-d H:i:s');
endif;
?>        
        
        GDownloadUrl("get_data.php?data_inicio=<?php print $data_inicio?>&data_fim=<?php print $data_fim?>", function(data) {
            var xml = GXml.parse(data);
            var bounds = xml.documentElement.getElementsByTagName("bounds");
            var minlat = bounds[0].getAttribute("minlat");
            var minlon = bounds[0].getAttribute("minlon");
            var maxlat = bounds[0].getAttribute("maxlat");
            var maxlon = bounds[0].getAttribute("maxlon");
            map.setCenter(new GLatLng((parseFloat(minlat)+parseFloat(maxlat))/2, (parseFloat(minlon)+parseFloat(maxlon))/2), 12);
            
            var trks = xml.documentElement.getElementsByTagName("trk");
            for (i=0;i<trks.length;i++) {
                //document.getElementById('rotas').innerHTML = trks[i].childNodes[0].textContent;
                var trkpts = trks[i].getElementsByTagName("trkpt");
                var pts = new Array();
                for (j=0;j<trkpts.length;j++) {
                    pts.push (new GLatLng(trkpts[j].attributes[0].value, trkpts[j].attributes[1].value));
                }
                var poly = new BDCCArrowedPolyline(pts,"#0000FF",2,0.5,null,40,6,"#FF0000",2,0.5);
                map.addOverlay(poly);
            }
        });     
        map.addControl(new ExtMapTypeControl({showTraffic: true, showTrafficKey: true}));
      }
    //]]>
    </script> 
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <table width="99%" height="99%">
        <tr valign="top">
            <td width="50">
                <div style="padding: 10px;">
                    <b><font face="Arial"><a href="/gps/">Home</a><br/><br/>
                    Hist&oacute;rico</b><br/>
<?php
$connection = new mysqli("localhost","gps","gpsDB","gps");
$query = "select distinct from_unixtime(time, '%Y-%m-%d') as 'date' from points order by time desc";
$result = $connection->query($query);
print '<ul>';
while ($row = $result->fetch_object()):
    print '<li><a href="/gps/index.php?data='.$row->date.'">'.$row->date.'</a><br/>';
endwhile;
print '</ul>';
?>
                </div>
            </td>
            <td height="100%">    
                <div id="map" style="float:left; width:100%; border:solid 2px gray;"></div>
            </td>
        </tr>
    </table>
  </body>
</html>
